<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="首月猫粮(万)" prop="firstMoney">
        <el-input
          v-model="queryParams.firstMoney"
          placeholder="请输入首月猫粮(万)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="续费猫粮" prop="renewMoney">
        <el-input
          v-model="queryParams.renewMoney"
          placeholder="请输入续费猫粮"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="返贵族猫粮值" prop="returnMoney">
        <el-input
          v-model="queryParams.returnMoney"
          placeholder="请输入返贵族猫粮值"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开通广播" prop="broadcast">
        <el-input
          v-model="queryParams.broadcast"
          placeholder="请输入开通广播"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开通特效" prop="effects">
        <el-input
          v-model="queryParams.effects"
          placeholder="请输入开通特效"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专属勋章" prop="medal">
        <el-input
          v-model="queryParams.medal"
          placeholder="请输入专属勋章"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="贵族坐席" prop="seat">
        <el-input
          v-model="queryParams.seat"
          placeholder="请输入贵族坐席"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="进场特效" prop="approach">
        <el-input
          v-model="queryParams.approach"
          placeholder="请输入进场特效"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专属名片" prop="card">
        <el-input
          v-model="queryParams.card"
          placeholder="请输入专属名片"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="加速升级" prop="accelerate">
        <el-input
          v-model="queryParams.accelerate"
          placeholder="请输入加速升级"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房间喇叭" prop="speaker">
        <el-input
          v-model="queryParams.speaker"
          placeholder="请输入房间喇叭"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="贵族聊天气泡" prop="bubble">
        <el-input
          v-model="queryParams.bubble"
          placeholder="请输入贵族聊天气泡"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="进房间隐私" prop="privacy">
        <el-input
          v-model="queryParams.privacy"
          placeholder="请输入进房间隐私"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="定制礼物" prop="customMade">
        <el-input
          v-model="queryParams.customMade"
          placeholder="请输入定制礼物"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="防禁言/防踢" prop="anti">
        <el-input
          v-model="queryParams.anti"
          placeholder="请输入防禁言/防踢"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专属管家" prop="housekeeper">
        <el-input
          v-model="queryParams.housekeeper"
          placeholder="请输入专属管家"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="榜单隐身" prop="stealth">
        <el-input
          v-model="queryParams.stealth"
          placeholder="请输入榜单隐身"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createDate">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.createDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:noble:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:noble:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:noble:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:noble:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="nobleList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="贵族名称" align="center" prop="name" />
      <el-table-column label="首月猫粮(万)" align="center" prop="firstMoney" />
      <el-table-column label="续费猫粮" align="center" prop="renewMoney" />
      <el-table-column label="返贵族猫粮值" align="center" prop="returnMoney" />
      <el-table-column label="开通广播" align="center" prop="broadcast" />
      <el-table-column label="开通特效" align="center" prop="effects" />
      <el-table-column label="专属勋章" align="center" prop="medal" />
      <el-table-column label="贵族坐席" align="center" prop="seat" />
      <el-table-column label="进场特效" align="center" prop="approach" />
      <el-table-column label="专属名片" align="center" prop="card" />
      <el-table-column label="加速升级" align="center" prop="accelerate" />
      <el-table-column label="房间喇叭" align="center" prop="speaker" />
      <el-table-column label="贵族聊天气泡" align="center" prop="bubble" />
      <el-table-column label="进房间隐私" align="center" prop="privacy" />
      <el-table-column label="定制礼物" align="center" prop="customMade" />
      <el-table-column label="防禁言/防踢" align="center" prop="anti" />
      <el-table-column label="专属管家" align="center" prop="housekeeper" />
      <el-table-column label="榜单隐身" align="center" prop="stealth" />
      <el-table-column label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:noble:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:noble:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改贵族设定对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="40%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="首月猫粮(万)" prop="firstMoney">
          <el-input v-model="form.firstMoney" placeholder="请输入首月猫粮(万)" />
        </el-form-item>
        <el-form-item label="续费猫粮" prop="renewMoney">
          <el-input v-model="form.renewMoney" placeholder="请输入续费猫粮" />
        </el-form-item>
        <el-form-item label="返贵族猫粮值" prop="returnMoney">
          <el-input v-model="form.returnMoney" placeholder="请输入返贵族猫粮值" />
        </el-form-item>
        <el-form-item label="开通广播" prop="broadcast">
          <el-input v-model="form.broadcast" placeholder="请输入开通广播" />
        </el-form-item>
        <el-form-item label="开通特效" prop="effects">
          <el-input v-model="form.effects" placeholder="请输入开通特效" />
        </el-form-item>
        <el-form-item label="专属勋章" prop="medal">
          <el-input v-model="form.medal" placeholder="请输入专属勋章" />
        </el-form-item>
        <el-form-item label="贵族坐席" prop="seat">
          <el-input v-model="form.seat" placeholder="请输入贵族坐席" />
        </el-form-item>
        <el-form-item label="进场特效" prop="approach">
          <el-input v-model="form.approach" placeholder="请输入进场特效" />
        </el-form-item>
        <el-form-item label="专属名片" prop="card">
          <el-input v-model="form.card" placeholder="请输入专属名片" />
        </el-form-item>
        <el-form-item label="加速升级" prop="accelerate">
          <el-input v-model="form.accelerate" placeholder="请输入加速升级" />
        </el-form-item>
        <el-form-item label="房间喇叭" prop="speaker">
          <el-input v-model="form.speaker" placeholder="请输入房间喇叭" />
        </el-form-item>
        <el-form-item label="贵族聊天气泡" prop="bubble">
          <el-input v-model="form.bubble" placeholder="请输入贵族聊天气泡" />
        </el-form-item>
        <el-form-item label="进房间隐私" prop="privacy">
          <el-input v-model="form.privacy" placeholder="请输入进房间隐私" />
        </el-form-item>
        <el-form-item label="定制礼物" prop="customMade">
          <el-input v-model="form.customMade" placeholder="请输入定制礼物" />
        </el-form-item>
        <el-form-item label="防禁言/防踢" prop="anti">
          <el-input v-model="form.anti" placeholder="请输入防禁言/防踢" />
        </el-form-item>
        <el-form-item label="专属管家" prop="housekeeper">
          <el-input v-model="form.housekeeper" placeholder="请输入专属管家" />
        </el-form-item>
        <el-form-item label="榜单隐身" prop="stealth">
          <el-input v-model="form.stealth" placeholder="请输入榜单隐身" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.createDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listNoble, getNoble, delNoble, addNoble, updateNoble, exportNoble } from "@/api/system/noble";

export default {
  name: "Noble",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 贵族设定表格数据
      nobleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        firstMoney: undefined,
        renewMoney: undefined,
        returnMoney: undefined,
        broadcast: undefined,
        effects: undefined,
        medal: undefined,
        seat: undefined,
        approach: undefined,
        card: undefined,
        accelerate: undefined,
        speaker: undefined,
        bubble: undefined,
        privacy: undefined,
        customMade: undefined,
        anti: undefined,
        housekeeper: undefined,
        stealth: undefined,
        createDate: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "贵族名称不能为空", trigger: "blur" }
        ],
        firstMoney: [
          { required: true, message: "首月猫粮(万)不能为空", trigger: "blur" }
        ],
        renewMoney: [
          { required: true, message: "续费猫粮不能为空", trigger: "blur" }
        ],
        returnMoney: [
          { required: true, message: "返贵族猫粮值不能为空", trigger: "blur" }
        ],
        broadcast: [
          { required: true, message: "开通广播不能为空", trigger: "blur" }
        ],
        effects: [
          { required: true, message: "开通特效不能为空", trigger: "blur" }
        ],
        medal: [
          { required: true, message: "专属勋章不能为空", trigger: "blur" }
        ],
        seat: [
          { required: true, message: "贵族坐席不能为空", trigger: "blur" }
        ],
        approach: [
          { required: true, message: "进场特效不能为空", trigger: "blur" }
        ],
        card: [
          { required: true, message: "专属名片不能为空", trigger: "blur" }
        ],
        accelerate: [
          { required: true, message: "加速升级不能为空", trigger: "blur" }
        ],
        speaker: [
          { required: true, message: "房间喇叭不能为空", trigger: "blur" }
        ],
        bubble: [
          { required: true, message: "贵族聊天气泡不能为空", trigger: "blur" }
        ],
        privacy: [
          { required: true, message: "进房间隐私不能为空", trigger: "blur" }
        ],
        customMade: [
          { required: true, message: "定制礼物不能为空", trigger: "blur" }
        ],
        anti: [
          { required: true, message: "防禁言/防踢不能为空", trigger: "blur" }
        ],
        housekeeper: [
          { required: true, message: "专属管家不能为空", trigger: "blur" }
        ],
        stealth: [
          { required: true, message: "榜单隐身不能为空", trigger: "blur" }
        ],
        createDate: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        createBy: [
          { required: true, message: "创建人不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "状态不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询贵族设定列表 */
    getList() {
      this.loading = true;
      listNoble(this.queryParams).then(response => {
        this.nobleList = response.rows;
        this.total = parseInt(response.total);
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        name: undefined,
        firstMoney: undefined,
        renewMoney: undefined,
        returnMoney: undefined,
        broadcast: undefined,
        effects: undefined,
        medal: undefined,
        seat: undefined,
        approach: undefined,
        card: undefined,
        accelerate: undefined,
        speaker: undefined,
        bubble: undefined,
        privacy: undefined,
        customMade: undefined,
        anti: undefined,
        housekeeper: undefined,
        stealth: undefined,
        createDate: undefined,
        createBy: undefined,
        status: "0"
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加贵族设定";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getNoble(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改贵族设定";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateNoble(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addNoble(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除贵族设定编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delNoble(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有贵族设定数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportNoble(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>